package org.linkerproject.server;

import java.util.ArrayList;

import org.imlinker.plugin.say.FanfouBot;
import org.linkerproject.html.HtmlContainer;
import org.linkerproject.html.HtmlLink;
import org.linkerproject.html.HtmlPage;
import org.linkerproject.html.HtmlText;
import org.linkerproject.message.MessageItem;

public class HomePage {

	public HomePage() {

		FanfouBot bot = new FanfouBot("tujf.cn@gmail.com", "tianxws");
		bot.initial();
		for (String m : bot.getMessages()) {
			messages.add(new MessageItem("", m));
		}

		page = new HtmlPage("Home");
		initial();
	}

	public void initial() {
		HtmlLink link = new HtmlLink("Home", "http://jindou/home");
		page.addBodyContent(link);
		link = new HtmlLink("Setting", "http://jindou/setting.html");
		page.addBodyContent(link);

		page.addBodyContent(new HtmlText("", "<hr />"));

		HtmlContainer container = new HtmlContainer("div");
		for (MessageItem item : messages) {
			HtmlText text = new HtmlText("div", item.getContent());
			container.addElement(text);
		}
		page.addBodyContent(container);

		pageHtmlStr = page.output();
	}

	public String display() {
		return pageHtmlStr;
	}

	private HtmlPage page;

	private String pageHtmlStr = "";

	private ArrayList<MessageItem> messages = new ArrayList<MessageItem>();

}
